package com.base.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.bean.Student;
import com.base.mapper.StudentMapper;

@Service
public class StudentService {
	
	@Autowired
	private StudentMapper studentMapper;
	
	public boolean save(Student student) {
		return studentMapper.insert(student) > 0;
	}

	public boolean delete(Long id) {
		return studentMapper.deleteByPrimaryKey(id) > 0;
	}

	public boolean update(Student student) {
		return studentMapper.updateByPrimaryKey(student) > 0;
	}

	public Student getStudent(Long id) {
		return null;
	}

	public Map<String, Object> getPageMap(Integer pageIndex,Integer pageSize) {
		Map<String, Object> pageMap = new HashMap<String, Object>();
		pageMap.put("count", getCount());
		pageMap.put("studentList", getPageList(pageIndex, pageSize));
		return pageMap;
	}
	
	public List<Student> getPageList(Integer pageIndex,Integer pageSize){
		return studentMapper.findPageList((pageIndex - 1) * pageSize,pageSize);
	}
	
	public Long getCount(){
		return studentMapper.count();
	}

}
